let express = require("express");
let path = require("path");
let svgCaptcha = require("svg-captcha");
let router = express.Router();

router.get("/in",(request,response) => {
    response.send("欢迎访问in首页" + request.time);
})

router.get("/on",(request,response) => {
    response.send("欢迎访问on首页" + request.time);
})

router.get("/login",(request,response) => {
    response.sendFile(path.resolve("./views/login.html"))
})

router.post("/dologin",(request,response) => {
    let {username,password} = request.body
    response.send(`登陆成功{${username},${password}}`)
})

router.post("/baoming",(req,res) => {
    let {username,password,sex} = req.body;
    res.send(`${username},${password},${sex},成功`)
})

router.get("/lei",(req,res) => {
    res.sendFile(path.resolve("./views/扫雷.html"))
})

// 响应svg验证码，生成图片
router.get("/yzm",(req,res) => {
    let options = {
        size:4,// 验证码长度
        width:100, //验证码图片宽度
        height:40, //验证码图片的高度
        background:"#873223", //验证码图片的背景颜色
        noise:4, //验证码图片中的干扰线
        fontSize:60, //验证码图片中文字大小
        color:true, //验证码图片中文字颜色
        ignoreChars:"i1o0" //容易混淆的字符不要出现在验证码中
    };
    let svg = svgCaptcha.create(options);
    console.log(svg);
    //svg.text为随机生成的字符串
    //svg.data为图形
    res.type("svg");
    res.send(svg.data);

})

module.exports = router;